#include "CImport.h"

#include <vtkSTLReader.h>
#include <vtkPolyDataMapper.h>
#include <QFileDialog>
#include <QSettings>
#include <QDir>
#include <QDebug>




vtkSmartPointer<vtkPolyData> CImport::import()
{
    QString defaultDir=QSettings().value("model/open",".").toString();
    QString defaultFilter=QSettings().value("model/filter","3D Models(*.stl *.STL);;All File(*.*)").toString();
    QString file= QFileDialog::getOpenFileName(0,tr("open"),defaultDir,defaultFilter);
    if(file.isEmpty())return 0;
    QDir dir(file);
    QSettings().setValue("model/open",dir.absolutePath());
    qDebug()<<"loading model "<<file<<" ... ";
    vtkSmartPointer<vtkSTLReader>reader=vtkSTLReader::New();
    reader->SetFileName(file.toUtf8().data());
    reader->Update();
    qDebug()<<"loaded model "<<file<<" . ";
    return reader->GetOutput();
}
